package com.example.rest.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.base.jdbc.DBSql;
import com.example.base.jdbc.SqlBuilder;
import com.example.base.sdk.SDK;
import com.example.base.security.SecurityUtil;
import com.example.base.security.SysUser;
import com.example.base.utils.RequestUtils;
import com.example.base.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/rest")
public class TestDemo2Controller {

    @GetMapping("/test")
    public JSONObject testController() throws IOException, SQLException {
        HttpServletRequest request= RequestUtils.getHttpServletRequest();
        if(request==null){
            System.out.println("request是空的");
        }else {
            System.out.println("request不是空的");
        }
        System.out.println("执行了1111111111   222222");
        SqlBuilder sqlBuilder=new SqlBuilder();
        sqlBuilder.select("*").from("m_note");

       List<Map<String,Object>> mapList= DBSql.getMaps(sqlBuilder.getSql());
       if(mapList!=null){
           mapList.forEach(map -> {
//               Timestamp timestamp=(Timestamp) map.get("create_time");
//               String str=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
//                map.put("create_time",str);
           });
       }
       SysUser sysUser= SecurityUtil.getSysUserEntity();
    //   JSONObject result= SDK.getSysUserByUserName("admin");
       JSONObject obj=new JSONObject();
       obj.put("data",mapList);
      // obj.put("user",result);
       obj.put("userId",sysUser.getUserName());
       return Result.successInfo("success",obj);
    }
}
